/**
 * Created by gaoyj on 2018/6/28.
 */
window.onload = function (ev) {
    topbar.hide();
};
var myDate = new Date();
var month = myDate.getMonth() + 1;
var day = myDate.getDate();
if (month < 10) {
    month = "0" + month;
}
if (day < 10) {
    day = "0" + day;
}
var _start = myDate.getFullYear() + '-' + month + '-' + day + " 00:00:00";
var _end = myDate.getFullYear() + '-' + month + '-' + day + " 23:59:59";
$("#startTime").val(_start);
$("#endTime").val(_end);
laydate.render({
    elem: '#startTime',
    type: 'datetime',

});
laydate.render({
    elem: '#endTime' //指定元素
    , type: 'datetime',
});
initArea();
var adminRole = roleCheck();
$('#dataTable').bootstrapTable({
    url: '/CollectCardReportController/actualSupplyCardReportPage',
    height: $(window).height() - 200,
    pageSize: 30,
    pagination: true,
    pageList: [30, 50, 100, 300],
    clickToSelect: true,
    queryParams: queryParams,
    uniqueId: 'id',
    queryParamsType: '',
    showFooter: true,
    sidePagination: 'server',
    responseHandler: function (res) {
        return {
            "total": res.total,
            "rows": res.resultList
        };
    },
    onClickRow: function (row) {
        if (row.userAccount != null && row.userAccount != '') {
            $("#account_field" + row.userAccount + row.cardOperatorName + row.face).html(row.userAccount);
        }
    },
    columns: [[
        {
            width: '3px',
            align: 'center',
            formatter: function (v, row, index) {
                return index + 1
            }
        }, {
            field: 'userAccount', title: '会员编号', width: 120, align: 'center',
            footerFormatter: function (value) {
                return "合计";
            },
            formatter:function(v,o){
                return copyAddon(v) + (adminRole == 1 ? v : userAccountHidden(o.userAccount,o.userAccount + o.cardOperatorName + o.face));
            }
        },
        {field: 'userName', title: '会员名称', width: 120, align: 'center'},
        {
            field: 'cardOperatorName', title: '运营商', width: 90, align: 'center'
        },
        {field: 'area', title: '销卡地区', width: 100, align: 'center'},
        {
            field: 'face', title: '面值', width: 100, align: 'center', footerFormatter: function (value) {
            var count = 0;
            for (var i in value) {
                count = parseFloat(count) + parseFloat(value[i].face);
            }
            return count.toFixed(4) + "";
        }
        },
        {
            field: 'sumFace', title: '销卡总面值', width: 100, align: 'center', footerFormatter: function (value) {
            var count = 0;
            for (var i in value) {
                count = parseFloat(count) + parseFloat(value[i].sumFace);
            }
            return count.toFixed(4) + "";
        }
        }
    ]]
});

$("#search").click(function () {
    var timeAdd = new Date($("#startTime").val());
    var timeEnd = new Date($("#endTime").val());
    if (timeAdd > timeEnd) {
        layer.msg("开始时间不能大于结束时间");
        return false;
    }
    var require = (timeEnd - timeAdd) / (1 * 24 * 60 * 60 * 1000);
    if (require > 7) {
        layer.msg("时间间隔不能超过7天");
        return;
    }
    $("#dataTable").bootstrapTable("refresh");
});
$(function () {
    $.ajax({
        type: "POST",
        url: "/CardProductController/queryAllCardOperatorList",
        dataType: "json",
        success: function (data) {
            $("#productType").html("");
            var str = "<option value=\"\">全部</option>";
            if (data != null && data.length > 0) {
                for (var i = 0; i < data.length; i++) {
                    str += '<option value=' + data[i].cardOperatorId + '>' + data[i].cardOperatorName + '</option>'
                }
            }
            $("#productType").append(str);
            //缺一不可  
            $('.selectpicker').selectpicker('refresh');
            $('.selectpicker').selectpicker('render');
        },
        beforeSend: function () {
        }
    });
})

function queryParams(params) {
    return {
        size: params.pageSize,
        page: params.pageNumber,
        area: $("#area").val(),
        startTime: $("#startTime").val(),
        endTime: $("#endTime").val(),
        productType: $("#productType").val(),
        face: $("#face").val(),
        userAccount: $("#account").val(),
    };
}